#!/usr/bin/env perl
use strict;

#total子程序，返回给定列表中数字相加的合
sub total {
	my ( @array ) = @_;
	my $total = 0;
	foreach my $item ( @array ) {
		$total += $item;
	}
	return $total;
}

#测试结果
my @fred = qw{ 1 3 5 7 9};
my $fred_total = &total( @fred );

#打印结果
print "$fred_total";
print "\n";

#计算1到1000的累加合
my @array_test = ();

for my $val (1..1000) {
	push( @array_test, $val );
}

my $test_total = &total( @array_test );
print "$test_total";

#用户输入数字，并计算总合
my $user_total = &total( <STDIN> );
print "$user_total";
